__author__ = 'karaayak'

import cv2, sys, numpy as np


def binarisierung(bild, schwellwert, max_wert):
    ret2,tresh = cv2.threshold(imgray,230,255,cv2.THRESH_BINARY)
    return tresh


if __name__ == "__main__":
    #pixelSize = 0.085*0.085
    anzahl = 0

    imgray = cv2.imread("confetti.jpg",cv2.CV_LOAD_IMAGE_GRAYSCALE)

    tresh = binarisierung(imgray, 230,255)

    contours, hierarchy = cv2.findContours(tresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    for contour in contours:
        if cv2.contourArea(contour)> 500:
            anzahl= anzahl +1
    print anzahl
    cv2.drawContours(imgray,contours,-1,(0,255,0),3)


    cv2.namedWindow("Aufgabe 2",cv2.CV_WINDOW_AUTOSIZE)
    cv2.imshow("Aufgabe 2",imgray)
    cv2.waitKey(0)


